package com.example.config;

import com.example.interceptor.Interceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
@Slf4j
public class WebConfig implements WebMvcConfigurer {

    @Resource
    private Interceptor interceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("添加拦截器");
        registry.addInterceptor(interceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/users/login"
                        , "/error"
                        , "/users/register"
                        , "/files/**"
                        , "/headerFiles/**"
                        , "/*.html"
                        , "/favicon.ico"
                        , "/*.js"
                        , "/admins/login"
                        , "/css/**"
                        , "/js/**"
                        , "/images/**"
                        , "/image/**"); // 这里可以排除不需要进行Token验证的路径
    }

}
